import { defineStore } from "pinia";
import axios from "../axios";

const marketStore = defineStore({
    id: 'marketStore',
    state: () => ({
        myCollectionList: []
    }),

    actions: {
        getMyCollectionList(data) {
            let thiss = this
            return new Promise((resolve, reject) => {
                axios.get('my_market_list', {params: data}).then(res => {
                    thiss.myCollectionList = res.data.data
                    resolve(res.data)
                }).catch(err => {
                    reject(err.data)
                })
            })
        },

        getCollectionDetail(data) {
            return new Promise((resolve, reject) => {
                axios.get('market', {
                    params: data
                }).then(res => {
                    resolve(res.data)
                }).catch(err => {
                    reject(err.data)
                })
            })
        },

        getSaleList(data) { 
            return new Promise((reslove, reject) => { 
                axios.get('sale_list', {params: data}).then(res => { 
                    reslove(res.data)
                }).catch(err => { 
                    reject(err.data)
                })
            })
        },

        give(payload) {
            return new Promise((resolve, reject) => {
                axios.post('give', payload).then((res) => {
                    resolve(res.data)
                }).catch(function (err) {
                    reject(err)
                })
            })
        },

        getGiveList (data) { 
            return new Promise((resolve, reject) => { 
                axios.get('give_list', {params: data}).then(res => { 
                    resolve(res.data)
                }).catch(err => { 
                    reject(err.data)
                })
            })
        },

        getGiveDetail (data) { 
            return new Promise((reslove, reject) => { 
                axios.get('give_detail', {params: data}).then(res => { 
                    reslove(res.data)
                }).catch(err => { 
                    reject(err.data)
                })
            })
        },

        getMarketList (data) { 
            return new Promise((reslove, reject) => { 
                axios.get('market_list', {params: data}).then(res => { 
                    reslove(res.data)
                }).catch(err => { 
                    reject(err.data)
                })
            })
        },

        // 寄售  修改寄售商品  取消和改价格
        marketUpdate (data) { 
            return new Promise((reslove, reject) => { 
                axios.post('market_update', data).then(res => { 
                    reslove(res.data)
                }).catch(err => { 
                    reject(err.data)
                })
            })
        },

        // 市场商品详情
        getMarketGoodsDetail (data) { 
            return new Promise ((reslove, reject) => { 
                axios.get('market', {params: data}).then(res => { 
                    reslove(res.data)
                }).catch(err => { 
                    reject(err.data)
                })
            })
        }
    }
})

export default marketStore